package com.qlh.camera

import com.qlh.camera.rgb.ImageUtil
import com.qlh.camera.rgb.ThresholdUtil
import com.sun.jna.ptr.DoubleByReference
import com.sun.jna.ptr.IntByReference
import org.opencv.core.*
import org.opencv.core.CvType.CV_8UC3
import org.opencv.imgcodecs.Imgcodecs
import org.opencv.imgproc.Imgproc
import java.io.File
import java.util.*
import javax.swing.JOptionPane
import javax.swing.UIManager

/*************************************************
 * 函数:       主函数
 * 函数描述:新建ClientDemo窗体并调用接口初始化SDK
 */


fun main(args: Array<String>) {
    initSystem()
}

private fun train(){
    //test()
    //writeBinData()
    //getBindToPic()
    //getKeyArea()
    //CNNUtil.trainNetwork()
    for (type in 1..3)
        getMt(type)

}

//初始化系统
private fun initSystem() {
    println("系统启动开始")
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel")
    } catch (e: Exception) {
        e.printStackTrace()
    }
    java.awt.EventQueue.invokeLater {
        if (!CameraClient.hCNetSDK.NET_DVR_Init()) {
            JOptionPane.showMessageDialog(null, "初始化失败")
        }
        val interfaceSetting = InterfaceSetting().apply {
            setResultInfoHeight(270)
        }
        CameraClient(interfaceSetting).apply {
            this.centerWindow()
            isVisible = true
        }
        println("系统启动完成")
    }

}


private fun getMt(type: Int) {
    val file = File("F:\\Private_Project\\data\\deal\\M$type")
    if (!file.isDirectory) return
    val files = file.listFiles()
    val sb = StringBuffer()
    for (f in files) {
        val mt = ThresholdUtil.getMT(f.absolutePath)
        if (sb.isEmpty()) {
            sb.append(mt)
        }else{
            sb.append(",")
            sb.append(mt)
        }
    }
    //写入文件
    ImageUtil.saveData(sb.toString())
}

private fun getSingleMT(testPath:String) = ThresholdUtil.getMT(testPath)